<?php
class OperatorButton extends CComponent {
	
	const STYLE_BLUE = 'pn pnc';
	const STYLE_GRAY = 'pn';
	
	const TARGET_BLANK = '_blank';
	const TARGET_SELF = '_self';
	const TARGET_PARENT = '_parent';
	
	const TYPE_NORMAL = 'button';
	const TYPE_SUBMIT = 'submitButton';
	const TYPE_RESET = 'resetButton';
	
	public $href = '';
	public $target = self::TARGET_SELF;
	public $htmlOptions = array();
	public $label;
	public $style = self::STYLE_BLUE;
	public $buttonType = self::TYPE_NORMAL;
	public $visible = true;
	
	public function generate() {
		$htmlOptions = $this->htmlOptions;
		$htmlOptions['class'] = isset($htmlOptions['class'])
			? $htmlOptions['class'] . ' ' . $this->style
			: $this->style;
		
		$htmlOptions['target'] = $this->target;
		$htmlOptions['href'] = $this->href;
		$htmlOptions['style'] = 'width:'.(strlen($this->label) * 12).'px';
		return call_user_func_array(array('CHtml', $this->buttonType), array(
			'label' => $this->label,
			'htmlOptions' => $htmlOptions,
		));
	}
	
}
?>